export function addZero (num: number) {
  return num < 10 ? `0${num}` : num
}

// 格式化时间
export function formatTime (time: string) {
  const date = new Date(time)
  const year = date.getFullYear()
  const month = addZero(date.getMonth() + 1)
  const day = addZero(date.getDate())
  const hour = addZero(date.getHours())
  const minite = addZero(date.getMinutes())
  const second = addZero(date.getSeconds())
  return `${year}-${month}-${day} ${hour}:${minite}:${second}`
}

// 格式化时间
export function convertTime (date: Date) {
  console.log('convertTime(formData.stackTime[0])', date)
  const year = date.getFullYear()
  // 注意：月份是从0开始的，所以需要+1
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hours = date.getHours()
  const minutes = date.getMinutes()
  const seconds = date.getSeconds()

  // 转换成年月日
  const dateString = year + '-' + month + '-' + day

  // 转换成年月日时分秒
  const dateTimeString = year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds

  return [ dateString, dateTimeString ]
}

// 获取当前时间
export function getNow () {
  const arr = [ '日', '一', '二', '三', '四', '五', '六' ]
  const date = new Date()
  const year = date.getFullYear()
  const month = addZero(date.getMonth() + 1)
  const day = addZero(date.getDate())
  const hour = addZero(date.getHours())
  const minite = addZero(date.getMinutes())
  const second = addZero(date.getSeconds())
  return `周${arr[date.getDay()]} ${year}-${month}-${day} ${hour}:${minite}:${second}`
}

export function takeMoreThan (value: number) {
  if (!value || value === 0) return value
  return Number(value.toString().match(/^\d+(?:\.\d{0,2})?/))
}